<?php

namespace wicked\process;

use wicked\core\Request;
use wicked\core\Session;
use wicked\core\Event;

class Initializer extends Runnable
{
    public function run()
    {
        Event::fire('initializer.start');

        // uri
        $uri = isset($_SERVER['QUERY_STRING']) ? trim($_SERVER['QUERY_STRING'], '/') : '';
        Request::uri($uri);

        // post data (not get)
        foreach($_POST as $key => $value)
            Request::post($key, $value);

        // ajax xml request
        $ajax = (bool)(array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
        Request::ajax($ajax);

        // mobile
        $mobile = (bool)(isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']));
        Request::mobile($mobile);

        // browser
        foreach(['Firefox', 'Safari', 'Chrome', 'Opera', 'MSIE'] as $browser)
            if(strpos($_SERVER['HTTP_USER_AGENT'], $browser))
                Request::browser($browser);

        Event::fire('initializer.end');
    }
}
